package com.smart.campus.web.controller.school;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.AppConfig;
import com.smart.campus.school.service.IAppConfigService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * app段配置项Controller
 * 
 * @author Zhihe.Li
 * @date 2020-12-02
 */
@Controller
@RequestMapping("/school/config")
public class AppConfigController extends BaseController
{
    private String prefix = "school/config";

    @Autowired
    private IAppConfigService appConfigService;

    @RequiresPermissions("school:config:view")
    @GetMapping()
    public String config()
    {
        return prefix + "/config";
    }

    /**
     * 查询app段配置项列表
     */
    @RequiresPermissions("school:config:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(AppConfig appConfig)
    {
        startPage();
        List<AppConfig> list = appConfigService.selectAppConfigList(appConfig);
        return getDataTable(list);
    }

    /**
     * 导出app段配置项列表
     */
    @RequiresPermissions("school:config:export")
    @Log(title = "app段配置项", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(AppConfig appConfig)
    {
        List<AppConfig> list = appConfigService.selectAppConfigList(appConfig);
        ExcelUtil<AppConfig> util = new ExcelUtil<AppConfig>(AppConfig.class);
        return util.exportExcel(list, "config");
    }

    /**
     * 新增app段配置项
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存app段配置项
     */
    @RequiresPermissions("school:config:add")
    @Log(title = "app段配置项", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(AppConfig appConfig)
    {
        return toAjax(appConfigService.insertAppConfig(appConfig));
    }

    /**
     * 修改app段配置项
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        AppConfig appConfig = appConfigService.selectAppConfigById(id);
        mmap.put("appConfig", appConfig);
        return prefix + "/edit";
    }

    /**
     * 修改保存app段配置项
     */
    @RequiresPermissions("school:config:edit")
    @Log(title = "app段配置项", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(AppConfig appConfig)
    {
        return toAjax(appConfigService.updateAppConfig(appConfig));
    }

    /**
     * 删除app段配置项
     */
    @RequiresPermissions("school:config:remove")
    @Log(title = "app段配置项", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(appConfigService.deleteAppConfigByIds(ids));
    }
}
